/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Decrypt.java
 *
 * Created on 11-10-2011, 10:41:42
 */

package gui;

import buz.StudentBuz;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.print.DocFlavor.READER;

/**
 *
 * @author XMANI
 */
public class Decrypt extends javax.swing.JFrame {

    StudentBuz sb = new StudentBuz();
    /** Creates new form Decrypt */
    public Decrypt() {
        
        initComponents();
        FileInputStream in = null;
        try {

            in = new FileInputStream("encrypt.txt");
            byte[] encryptText = new byte[in.available()];
            in.read(encryptText);
            String s = new String(encryptText);
            txaEncrypt.setText(s);
        } catch (IOException ex) {
            Logger.getLogger(Decrypt.class.getName()).log(Level.SEVERE, null, ex);
        }  finally {
            try {
                in.close();
            } catch (IOException ex) {
                Logger.getLogger(Decrypt.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        scpEn = new javax.swing.JScrollPane();
        txaEncrypt = new javax.swing.JTextArea();
        scpDe = new javax.swing.JScrollPane();
        txaDecrypt = new javax.swing.JTextArea();
        btnDecrypt = new javax.swing.JButton();
        lblEn = new javax.swing.JLabel();
        lblDe = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        txaEncrypt.setColumns(20);
        txaEncrypt.setRows(5);
        scpEn.setViewportView(txaEncrypt);

        txaDecrypt.setColumns(20);
        txaDecrypt.setRows(5);
        scpDe.setViewportView(txaDecrypt);

        btnDecrypt.setText("Decrypt");
        btnDecrypt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDecryptActionPerformed(evt);
            }
        });

        lblEn.setText("Encrypt");

        lblDe.setText("Decrypt");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblEn)
                    .addComponent(scpEn, javax.swing.GroupLayout.PREFERRED_SIZE, 317, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(lblDe)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 208, Short.MAX_VALUE)
                        .addComponent(btnDecrypt))
                    .addComponent(scpDe, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addComponent(lblEn)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scpEn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnDecrypt)
                    .addComponent(lblDe))
                .addGap(18, 18, 18)
                .addComponent(scpDe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-353)/2, (screenSize.height-344)/2, 353, 344);
    }// </editor-fold>//GEN-END:initComponents

    private void btnDecryptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDecryptActionPerformed
        FileInputStream in = null;
        try {
            // TODO add your handling code here:
            sb.decriypt();
            in = new FileInputStream("decrypt.txt");
            byte[] DecriyptText = new byte[in.available()];
            in.read(DecriyptText);
            String s = new String(DecriyptText);
            txaDecrypt.setText(s);
        } catch (IOException ex) {
            Logger.getLogger(Decrypt.class.getName()).log(Level.SEVERE, null, ex);
        }  finally {
            try {
                in.close();
            } catch (IOException ex) {
                Logger.getLogger(Decrypt.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }//GEN-LAST:event_btnDecryptActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Decrypt().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnDecrypt;
    private javax.swing.JLabel lblDe;
    private javax.swing.JLabel lblEn;
    private javax.swing.JScrollPane scpDe;
    private javax.swing.JScrollPane scpEn;
    private javax.swing.JTextArea txaDecrypt;
    private javax.swing.JTextArea txaEncrypt;
    // End of variables declaration//GEN-END:variables

}
